package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.common.properties.AliOssProperties;
import com.atguigu.lease.common.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置类，用于创建AliOssUtil对象
 */
@Configuration
public class OssConfiguration {
    @Bean
    @ConditionalOnMissingBean//让IOC容器中只有一个实例对象
    //当作为参数出现时,spring会自动注入aliOssProperties，不需要显示出现
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties){
        return new AliOssUtil(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName());
    }
}
